package com.eBook.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eBook.dao.UserDao;
import com.eBook.entity.User;
import com.eBook.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;
	
	/*
	 * 用于登录，根据用户account返回登录的用户
	 * 如果用户是第一次登录，将该用户添加到数据库
	 * */
	@Override
	public User userLogin(User user) {
		User u = userDao.findUserByAccount(user);
		if(u == null){
			userRegister(user);
		}
		u = userDao.findUserByAccount(user);
		return u;
	}
	/*
	 * 用户注册
	 * return：成功返回true，失败返回false
	 * **/
	@Override
	public boolean userRegister(User user) {
		int flag = userDao.addUser(user);
		return flag == 1;
	}
	@Override
	public boolean updateBonus(Map<String, Integer> userBonus) {
		int flag = userDao.updateBonus(userBonus);
		return flag == 1;
	}
	@Override
	public boolean updateVip(Map<String, String> userVip) {
		int flag = userDao.updateVipCount(userVip);
		return flag == 1;
	}
	@Override
	public boolean updateCount(Map<String, String> userCount) {
		int flag = userDao.updateCount(userCount);
		return flag == 1;
	}
	
}
